package test.fontGDX;

import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

public class FontGame extends Game{
	
	SpriteBatch spriteBatch;
	BitmapFont font14;
	BitmapFont font16;
	BitmapFont font20;
	BitmapFont font24;
	Texture texture;
	
	@Override
	public void create() {
		spriteBatch = new SpriteBatch();
		
		FileHandle fontFile;
		FileHandle fontFilePNG;

		fontFile = Gdx.files.classpath("res/font/ArialBold14.fnt");
		fontFilePNG = Gdx.files.classpath("res/font/ArialBold14.png");
		font14 = new BitmapFont(fontFile, fontFilePNG, false);
		
		fontFile = Gdx.files.classpath("res/font/ArialBold16.fnt");
		fontFilePNG = Gdx.files.classpath("res/font/ArialBold16.png");
		font16 = new BitmapFont(fontFile, fontFilePNG, false);
		
		fontFile = Gdx.files.classpath("res/font/ArialBold20.fnt");
		fontFilePNG = Gdx.files.classpath("res/font/ArialBold20.png");
		font20 = new BitmapFont(fontFile, fontFilePNG, false);
		
		fontFile = Gdx.files.classpath("res/font/ArialBold24.fnt");
		fontFilePNG = Gdx.files.classpath("res/font/ArialBold24.png");
		font24 = new BitmapFont(fontFile, fontFilePNG, false);
		
		
		Pixmap pixmap = new Pixmap(512, 512, Format.RGBA8888);
		pixmap.setColor(Color.WHITE);
		pixmap.fillRectangle(0, 0, 512, 512);
		texture = new Texture(pixmap);
		pixmap.dispose();

	}
	
	@Override
	public void render() {
		spriteBatch.begin();
		spriteBatch.draw(texture, 0, 0);
		
		font14.setColor(1,0,0,1);
		font14.draw(spriteBatch, "hello world", 100, 100);
		
		font16.setColor(1,0,0,1);
		font16.draw(spriteBatch, "hello world", 100, 120);
		
		font20.setColor(1,0,0,1);
		font20.draw(spriteBatch, "hello world", 100, 140);
		
		font24.setColor(1,0,0,1);
		font24.draw(spriteBatch, "hello world", 100, 160);
		
		spriteBatch.end();
	}
	
	@Override
	public void dispose() {
		super.dispose();
	}
	
	public static void main(String args[]) {
		LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
		config.vSyncEnabled = true;
		config.samples = 4;
		config.useCPUSynch = true;
		config.title = "Protect Castle";
		config.width = 800;
		config.height = 600;	
		config.fullscreen = false;
		
		new LwjglApplication(new FontGame(), config);
	}

}
